/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AuctionsGUI.java
 *
 * Created on Oct 7, 2011, 8:03:27 PM
 */

package auctions;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
 *
 * @author zxyang
 */
public class AuctionsGUI extends javax.swing.JFrame {

    private int k_para; //number of auctions
	private int n_para; // paymentrule
    private int nb_para; //number of bidders
    private double rp_para; //reserve price
    private String filename; //output file
    private Vector<Integer> prs;// payment rules
    private Vector<Double> rps;
    private Vector<Integer> auctTypes; // ascending, descending, sealed bid...
    private Vector<Agent> agents;
    private Vector<AuctionResults> results;
    private Vector<BidderResults> bresults;
    private AuctionHouse auctions;
    private javax.swing.JFrame frame;
    private int index;
    private int topAuctType; //simultaneous, sequential
    private Vector<Double> utls;
    /** Creates new form AuctionsGUI */
    public AuctionsGUI() {
        topAuctType = 1;
        auctTypes = new Vector<Integer>();
        k_para = 5;
        n_para = 2;
        nb_para = 4;
        rps = new Vector<Double>();
        prs = new Vector<Integer>();
        utls = new Vector<Double>();
        filename="auction_results";
        results = new Vector<AuctionResults>();
        bresults = new Vector<BidderResults>();
        agents = new Vector<Agent>();
        index=1;
        frame = new JFrame();
        initComponents();
        jPanel4.setVisible(false);
        this.start.setVisible(false);
        //this.jScrollPane1.setVisible(false);
        buttonGroup1.setSelected(simultaneous_button.getModel(), true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        messageBox = new javax.swing.JOptionPane();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel3 = new javax.swing.JPanel();
        start = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        k_Field = new javax.swing.JTextField();
        k_Label = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        nb_field = new javax.swing.JTextField();
        auctType_Label = new javax.swing.JLabel();
        simultaneous_button = new javax.swing.JRadioButton();
        sequential_button = new javax.swing.JRadioButton();
        submitOne = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        resultsArea = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        rpLabel = new javax.swing.JLabel();
        rp_field = new javax.swing.JTextField();
        submitTwo = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        auctType_field = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        pr_label = new javax.swing.JLabel();
        n_Field = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        start.setText("Start Bidding!");
        start.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(start)
                .addContainerGap(424, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(start)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        k_Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                k_FieldActionPerformed(evt);
            }
        });

        k_Label.setText("Please enter number of  auctions:");

        jLabel1.setText("Please enter the number of bidders:");

        auctType_Label.setText("Please choose how auctions are held:");

        buttonGroup1.add(simultaneous_button);
        simultaneous_button.setText("Simultaneous");
        simultaneous_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simultaneous_buttonActionPerformed(evt);
            }
        });

        buttonGroup1.add(sequential_button);
        sequential_button.setText("Sequential");
        sequential_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sequential_buttonActionPerformed(evt);
            }
        });

        submitOne.setText("submit");
        submitOne.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitOneActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(k_Label)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 249, Short.MAX_VALUE)
                    .addComponent(auctType_Label, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(simultaneous_button)
                        .addGap(18, 18, 18)
                        .addComponent(sequential_button)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nb_field, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
                            .addComponent(k_Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(80, 80, 80)
                        .addComponent(submitOne)
                        .addGap(227, 227, 227))))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {k_Field, nb_field});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(auctType_Label, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(simultaneous_button)
                    .addComponent(sequential_button))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(nb_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(k_Label, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(k_Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(submitOne)))
                .addContainerGap())
        );

        resultsArea.setColumns(20);
        resultsArea.setRows(5);
        jScrollPane1.setViewportView(resultsArea);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        rpLabel.setText("Please enter the nth auction's reserve price:");

        submitTwo.setText("Next");
        submitTwo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitTwoActionPerformed(evt);
            }
        });

        jLabel2.setText("Please enter the nth auction's type:");

        jLabel3.setText("Ascending:1   Descending:2    Sealed Bid:3");

        pr_label.setText("Please enter the nth auction's payment rule number");

        n_Field.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                n_FieldActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(588, 588, 588))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(rpLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING))
                                .addGap(72, 72, 72)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(auctType_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(rp_field, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                .addComponent(pr_label)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(n_Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addComponent(submitTwo)
                        .addContainerGap())))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {auctType_field, n_Field, rp_field});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pr_label)
                    .addComponent(n_Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(auctType_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rpLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rp_field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(submitTwo)))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {auctType_field, n_Field, rp_field});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 541, Short.MAX_VALUE)
                    .addComponent(jPanel4, 0, 541, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void startActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startActionPerformed
        /**
         * create auctions
         */

        Vector<AuctionType> at = new Vector<AuctionType>();
        for( int i=0; i< auctTypes.size(); i++){
                if(auctTypes.get(i)==1){
                    at.add(AuctionType.ASCENDING);
                }
                else if (auctTypes.get(i)==2){
                    at.add(AuctionType.DESCENDING);
                }
                else{
                    at.add(AuctionType.SEALEDBID);
                }
            }       
        if(topAuctType==1){
            System.out.println("Simultaneous Auction House");
            auctions = new SimultaneousAuctionHouse(filename, null,prs,rps, at);
        }
        else{
            System.out.println("Sequential Auction House");
            auctions = new SequentialAuctionHouse(filename, null, prs, rps, at);
        }
 
        /**
         * create bidders
         */
        this.agents.clear();
        
        for (int i= 0; i< nb_para; i++){
            Vector<Double> utility = new Vector<Double>();
            for(int j =0; j< k_para; j++){
                Double u = Math.random()*10;
                utility.add(j,u);
            }
            Agent agent;
            if(topAuctType==1){
               
               agent = new SimultaneousDummyAgent(auctions,utility);
                   
            }
            else {
               agent = new SequentialDummyAgent(auctions,utility);
            }
            
            agents.add(agent);
        }

        /**
          * run
          */
        
        auctions.setAgents(agents);
        Results allresults = auctions.getWinners();
        results = allresults.getAuctionResults();
        bresults = allresults.getBidderResults();
        String text = "\n"+auctions.getType().toString()+"\n\n";

        for (int i =1; i<= k_para; i++){
            String auctionName = "Auction #"+i+" ("+auctions.getAuctionTypes().get(i-1).toString()
                    +", "+this.prs.get(i-1)+" price)";
            Vector<AuctionResults> ars = auctions.getAuction(i-1).getAuctionResults();
            String txt ="";
            for(int m=0; m< ars.size(); m++){
                AuctionResults ar = ars.get(m);
                String roundName = "\tRound #";
                String name = roundName.concat(Integer.toString(m+1)+"\n");
                String winningPrice = ConvertType.strPre(ar.getWinningPrice());
                Vector<Double> bids = ar.getBids();
                String bidsname = "";
                for(int j=0; j< nb_para; j++){
                    String bid = ConvertType.strPre(bids.get(j));
                    bidsname=bidsname+bid+", ";
                }
                String winningBidder = Integer.toString(ar.getWinningBidder()+1);
                String temp1 = name.concat("\t\tWinning Price: "+winningPrice+"\n\t\tBids: "+bidsname+"\n\t\tWinning Bidder: "+winningBidder+"\n");
                txt =txt.concat(temp1);
            }
            text = text.concat(auctionName+"\n"+txt+"\n");
        }

        for (int i =1; i<= nb_para; i++){
            BidderResults br = bresults.get(i-1);
            String auctionName = "Bidder #";
            String name = auctionName.concat(Integer.toString(i));
            String revenue = ConvertType.strPre(br.getRevenue());
            String profit = ConvertType.strPre(br.getProfit());
            String cost = ConvertType.strPre(br.getCost());
            Vector<Integer> items = br.getItemsWon();
            Iterator<Integer> itr = items.iterator();
            String itemsWon="";
            while(itr.hasNext()){
                int item = itr.next()+1;
                itemsWon = itemsWon+item+" ";
            }
            if(itemsWon.length()==0)
                itemsWon = "none";
            String temp1 = name.concat("\n\tRevenue: "+revenue+"\n\tprofit: "+profit+"\n\tCost: "+cost+"\n\tItems Won: "+itemsWon+"\n\n");
            text =text.concat(temp1);
        }
        resultsArea.setText(text);

    }//GEN-LAST:event_startActionPerformed

    private void k_FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_k_FieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_k_FieldActionPerformed

    private void sequential_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sequential_buttonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sequential_buttonActionPerformed

    private void simultaneous_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simultaneous_buttonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_simultaneous_buttonActionPerformed

    private void submitOneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitOneActionPerformed
        
        if(sequential_button.getModel()==buttonGroup1.getSelection()){
          
            topAuctType=2;
        }
        else{
            topAuctType=1;
        }

        try {
            nb_para = Integer.parseInt(nb_field.getText());
            if(nb_para<=0||nb_para>1000){
                JOptionPane.showMessageDialog(frame, "Please enter an integer between 1 and 1000!");
                nb_field.setText("");
                return;
            }
        }
        catch(NumberFormatException nFE) {
            JOptionPane.showMessageDialog(frame, "Please enter an integer!");
            nb_field.setText("");
            return;
        }

        try {
            k_para = Integer.parseInt(k_Field.getText());
            if(k_para<=0||k_para>100){
                JOptionPane.showMessageDialog(frame, "Please enter an integer between 1 and 100!");
                k_Field.setText("");
                return;
            }
        }
        catch(NumberFormatException nFE) {
            JOptionPane.showMessageDialog(frame, "Please enter a integer number!");
            k_Field.setText("");
            return;
        }
                
        String prl1 = "Please enter the payment rule for aution #1:";
        pr_label.setText(prl1);
        
        String atypel1 = "Please enter the type of auction #1:";
        jLabel2.setText(atypel1);
        
        String rpl1 = "Please enter the reserve price for auction #1:";
        rpLabel.setText(rpl1);
        jPanel4.setVisible(true);

        this.rps.clear();
        this.prs.clear();
        this.auctTypes.clear();
        
}//GEN-LAST:event_submitOneActionPerformed

    private void submitTwoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitTwoActionPerformed
        int auctType=1;
        try {
            auctType = Integer.parseInt(auctType_field.getText());
            if(auctType<=0||auctType>3){
                JOptionPane.showMessageDialog(frame, "Please enter an integer between 1 and 3!");
                auctType_field.setText("");
                return;
            }
        } catch(NumberFormatException nFE) {
            JOptionPane.showMessageDialog(frame, "Please enter a number!");
            auctType_field.setText("");
            return;
        }

        try {
            n_para = Integer.parseInt(n_Field.getText());
            if(n_para<=0||n_para>100){
                JOptionPane.showMessageDialog(frame, "Please enter an integer between 1 and 100!");
                return;
            }
        }
        catch(NumberFormatException nFE) {
            JOptionPane.showMessageDialog(frame, "Please enter a number!");
            n_Field.setText("");
            return;
        }

        try {
            rp_para = Integer.parseInt(rp_field.getText());
            if(rp_para<=0||nb_para>100){
                JOptionPane.showMessageDialog(frame, "Please enter an integer between 1 and 100!");
                rp_field.setText("");
                return;
            }
        } catch(NumberFormatException nFE) {
            JOptionPane.showMessageDialog(frame, "Please enter a number!");
            rp_field.setText("");
            return;
        }
        double rp = Double.parseDouble(rp_field.getText());
        rps.add(index-1,rp);
        rp_field.setText("");
        auctTypes.add(index-1,auctType);
        auctType_field.setText("");
        prs.add(index-1,n_para);
        n_Field.setText("");
        index++;
        if(index<=k_para){
            String rpl1 = "Please enter the reserve price for auction #";
            String rpl = rpl1.concat(Integer.toString(index)+":");
            rpLabel.setText(rpl);
            String atl1 = "Please enter the type of auction #";
            String atl = atl1.concat(Integer.toString(index)+":");
            jLabel2.setText(atl);
            String prl1 = "Please enter the payment rule for auction:";
            String prl = prl1.concat(Integer.toString(index)+":");
            pr_label.setText(prl);
        } else{
            index=1;
            jPanel4.setVisible(false);
            this.start.setVisible(true);;
            //this.jScrollPane1.setVisible(true);
        }
}//GEN-LAST:event_submitTwoActionPerformed

    private void n_FieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_n_FieldActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_n_FieldActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AuctionsGUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel auctType_Label;
    private javax.swing.JTextField auctType_field;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField k_Field;
    private javax.swing.JLabel k_Label;
    private javax.swing.JOptionPane messageBox;
    private javax.swing.JTextField n_Field;
    private javax.swing.JTextField nb_field;
    private javax.swing.JLabel pr_label;
    private javax.swing.JTextArea resultsArea;
    private javax.swing.JLabel rpLabel;
    private javax.swing.JTextField rp_field;
    private javax.swing.JRadioButton sequential_button;
    private javax.swing.JRadioButton simultaneous_button;
    private javax.swing.JButton start;
    private javax.swing.JButton submitOne;
    private javax.swing.JButton submitTwo;
    // End of variables declaration//GEN-END:variables

}
